package com.zrrd.product.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.zrrd.common.result.Result;
import com.zrrd.model.product.SkuInfo;
import com.zrrd.model.product.SpuInfo;
import com.zrrd.product.service.SkuInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin/product")
public class SkuInfoController {
    @Autowired
    private SkuInfoService skuInfoService;

    //列表
    @GetMapping("/list/{page}/{limit}")
    public Result<Page> list(@PathVariable("page") Integer page, @PathVariable("limit") Integer limit) {
        Page<SkuInfo> skuInfoPage = new Page<>(page, limit);
        skuInfoService.page(skuInfoPage, null);
        return Result.ok(skuInfoPage);

    }

    //上架
    @GetMapping("/onSale/{skuId}")
    public Result<String> on(@PathVariable Long skuId){
     SkuInfo skuInfo=new SkuInfo();
     skuInfo.setId(skuId);
     skuInfo.setIsSale(1);
     skuInfoService.updateById(skuInfo);
     return Result.ok("上架");
    }

    //下架
    @GetMapping("/cancelSale/{skuId}")
    public Result<String> canceSale(@PathVariable Long skuId){
        SkuInfo skuInfo=new SkuInfo();
        skuInfo.setId(skuId);
        skuInfo.setIsSale(0);
        skuInfoService.updateById(skuInfo);
        return Result.ok("下架");
    }
}
